<template>
  <div class="app-container ">
    <el-row ref="refbut">
      <el-col :span="24" style="">
        <el-card class="box-card">
          <el-form>
            <el-form-item label="任务名称">
              <el-select v-model="nameId" placeholder="请选择任务名称" style="width:300px" @change="selectChange">
                <el-option v-for='item in selectlist' :key="item.ID" :label="item.JIANDINGRENWUNAME"
                           :value="item.ID"></el-option>
              </el-select>
            </el-form-item>
          </el-form>
          <!--                    <el-row>-->
          <!--                        <el-col :span="12"> <el-descriptions title="" :column="4">-->
          <!--                                <el-descriptions-item label="任务总数">{{ numInfo.ALLNUM }}</el-descriptions-item>-->
          <!--                                <el-descriptions-item label="已审定">{{ numInfo.ALLNUM - numInfo.HADSH-->
          <!--                                }}</el-descriptions-item>-->
          <!--                                &lt;!&ndash; <el-descriptions-item label="审查进度">{{ numInfo.PERCENTAGE }}-->

          <!--                                </el-descriptions-item> &ndash;&gt;-->
          <!--                            </el-descriptions></el-col>-->
          <!--                    </el-row>-->

        </el-card>

        <el-row>
          <el-col :span="24" style="margin-top:20px">
            <el-form ref="queryForm"  :inline="true" v-show="showSearch">
              <el-form-item label="" v-for="(item, index) in listFrom" :key="index">
                <span slot="label">{{ item.FIELD_CAPTION }} </span>
                <input_item :item="item" @onChangeTap="onChangeTap" :inputType="1"
                            :inputParams="queryParams">
                </input_item>
              </el-form-item>
              <el-form-item label="初审结果">
                <el-select placeholder="请选择" v-model="listQueryParams.chushenresult">
                  <el-option v-for="item in dict.type.IS_OPENS" :key="item.value" :label="item.label"
                             :value="item.value"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="复审结果">
                <el-select placeholder="请选择" v-model="listQueryParams.fushenresult">
                  <el-option v-for="item in dict.type.IS_OPENS" :key="item.value" :label="item.label"
                             :value="item.value"></el-option>
                </el-select>
              </el-form-item>

              <el-form-item>
                <el-button type="primary" icon="el-icon-search"
                           @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh"  @click="resetQuery">重置</el-button>
              </el-form-item>
            </el-form>
          </el-col>
          <el-col :span="24">
            <el-divider></el-divider>
          </el-col>
        </el-row>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" plain icon="el-icon-plus"  @click="submitTap">提交</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="sdlistPOST"></right-toolbar>
        </el-row>
      </el-col>
    </el-row>
    <tableList :tableHeaderList="tableHeaderList" :tableData="tableData" :loading="loading" :tableHeight="tableHeight"
               @celldblclick="celldblclick" @sortChange="sortChange" @handleSelectionChange="handleSelectionChange"
               @handleSDJGDeit="handleSDJGDeit" :isShending="isShending" :isSelection="false" :iskfjdorbgqx="iskfjdorbgqx" ref="ref">
    </tableList>
    <pagination v-show="total > 0" :total="total" :page.sync="listQueryParams.pageNum"
                :limit.sync="listQueryParams.pageSize" @pagination="sdlistPOST" />
    <!--start  组件详情 -->
    <jianDetailsOpen v-if="jianDetailsOpen" :open="jianDetailsOpen" :celldbData="celldbData"
                     @detailsHandleClose="detailsHandleClose">
    </jianDetailsOpen>
    <!--end 组件详情 -->
    <!-- start 组卷\项目详情 -->
    <juanDetailsOpen v-if="juanDetailsOpen" :open="juanDetailsOpen" :celldbData="celldbData"
                     @detailsHandleClose="detailsHandleClose" :chuFushenParams="chuFushenParams">
    </juanDetailsOpen>
    <!-- end 组卷\项目详情 -->


  </div>
</template>
<script>
import { getsdjoblist, sdlist, shendingtijiao, changesdresult } from "@/api/archive/archivalAppraisal/openness/openArchivesAuthorize"
import { getqueryfieldList, getshowfield } from "@/api/archive/fileCollection/offlinReception"
import { getGroupTree } from "@/api/archive/archivesCategory.js"
import { getInfo } from "@/api/login.js"
import input_item from "@/components/input/index.vue"
import estimateTableHeight from '@/mixins/estimateTableHeight';
import tableList from "@/components/tableList/index.vue"
import jianDetailsOpen from '@/components/componentsJianDetails/index.vue' //件详情
import juanDetailsOpen from '@/components/componentsJuanDetails/index.vue' //卷详情
export default {
  archive_Dicts: ['IS_OPENS'],
  mixins: [estimateTableHeight], // 混入方法
  components: {
    input_item,
    tableList,
    jianDetailsOpen,
    juanDetailsOpen
  },
  data() {
    return {
      // iskfjdorbgqx:0 //:iskfjdorbgqx="0"  开放鉴定   :iskfjdorbgqx="1" 保管期限
      iskfjdorbgqx: "0",
      loading: false,
      listFrom: [], //查询框列表
      showSearch: true,// 显示搜索条件
      queryParams: {},
      listQueryParams: {
        searchcolumn: undefined,//查询参数
        pageNum: 1,
        pageSize: 10,
        order: undefined,
        chushenresult: undefined,//初审结果
        fushenresult: undefined,//复审结果
        fields: undefined,
        ids: undefined,
      },
      nameId: "",
      selectlist: "",
      numInfo: { //获取任务总数
        "NOWPERSON": 0, //当前人分配数
        "HADSH": 0,   //已审核数
        "ALLNUM": 0,  //总数
        "PERCENTAGE": "0%",//占比
      },
      rowNameIDrow: "", //当前下拉数据
      tableHeaderList: [],
      tableData: [],
      total: 0,
      single: true,
      multiple: true,
      isSelection: false,
      jianDetailsOpen: false,
      juanDetailsOpen: false,
      rowInfo: "",
      chuFushenParams: "",
      isShending: true
    }
  },
  created() {

    this.getsdjoblistPOST();

  },
  methods: {

    // 获取审定任务
    getsdjoblistPOST() {
      getsdjoblist().then(res => {
        if (res.code == "200") {
          if (res.data.length > 0) {
            this.selectlist = res.data;
            this.rowNameIDrow = res.data[0];
            this.nameId = res.data[0].ID
            this.listQueryParams.renwuid = this.rowNameIDrow.ID
            // this.getInfoPOST(); //获取当前用户的ID 根据ID获取任务总数/当前人分配数/待审核数/占比
            this.getGroupTreePost(); //档案门类树门类详情，根据详情获取查询列表
            this.getshowfieldPost() //列表
          }else{
            this.rowNameIDrow = "";
            this.nameId = ""
            this.listQueryParams.renwuid = undefined
            this.tableHeaderList = [];
            this.tableData = [];
          }
        }
      })
    },
    //下拉事件
    selectChange() {
      this.queryParams = {};
      this.listQueryParams.pageNum = 1;
      this.listQueryParams.pageSize = 10;
      this.listQueryParams.searchcolumn = undefined;
      this.listQueryParams.chushenresult = undefined;
      this.listQueryParams.order = undefined;
      this.listQueryParams.fushenresult = undefined
      var rowNameIDrow = this.selectlist.filter(res => {
        return res.ID == this.nameId
      })
      this.rowNameIDrow = rowNameIDrow[0];
      this.listQueryParams.renwuid = this.rowNameIDrow.ID
      this.getInfoPOST(); //获取当前用户的ID 根据ID获取任务总数/当前人分配数/待审核数/占比
      this.getGroupTreePost(); //档案门类树门类详情，根据详情获取查询列表
      this.getshowfieldPost() //列表
    },

    //获取当前用户的ID
    getInfoPOST() {
      getInfo().then(res => {
        this.getchushennumPOST(res.user.userId);
      })
    },
    //获取当前人审定任务
    getchushennumPOST(userId) {
      getchushennum(this.nameId, userId).then(res => {
        this.numInfo = res.data;
      })
    },

    //档案门类树门类根据categoryID回显 /** 获取查询字段 */
    getGroupTreePost() {
      getGroupTree(this.rowNameIDrow.CATEGORYID).then(response => {
        var SUB_TABLE_NAME = ""
        if (this.rowNameIDrow.TYPE == "f") {//件
          SUB_TABLE_NAME = response.data.fileTableName;
        } else if (this.rowNameIDrow.TYPE == "v") { //卷
          SUB_TABLE_NAME = response.data.folderTableName;
        } else {//项目
          SUB_TABLE_NAME = response.data.itemTableName;
        }
        this.listQueryParams.subTableName = SUB_TABLE_NAME
        /** 获取查询字段 */
        getqueryfieldList({
          categoryId: this.rowNameIDrow.CATEGORYID,
          menuId: this.$route.meta.menuId,
          subTableName: SUB_TABLE_NAME
        }).then(response => {
          this.listFrom = response.rows;
        });
      });
    },

    closeDelDialog() {
      this.$emit("closeDelDialog")
    },

    onChangeTap(data) {
      var dataArr=""
      if(data.val!=undefined){
        dataArr = data.queryParams;
      }else{
        dataArr = data;
      }
      if (this.queryParams.length > 0) {
        for (var i in this.queryParams) {
          if (Object.keys(this.queryParams[i]).toString() == Object.keys(data).toString()) {
            this.queryParams.splice(i, 1)
          }
        }
        this.queryParams = dataArr;
      } else {
        this.queryParams = dataArr;
      }

    },
    handleQuery() {
      var searchcolumn = []
      for (var k in this.listFrom) {
        for (var i in this.queryParams) {
          if (this.queryParams[i] != null) {
            if (this.listFrom[k].FIELD_NAME == i) {
              if (this.listFrom[k].SHOWTYPE == 3 && this.listFrom[k].IS_QUERY == 4) {
                searchcolumn.push({
                  "queryType": this.listFrom[k].IS_QUERY,
                  "showType": this.listFrom[k].SHOWTYPE,
                  "column": this.listFrom[k].FIELD_NAME,
                  "value": this.queryParams[i][0],
                  "valueTwo": this.queryParams[i][1],
                })
              } else if (this.listFrom[k].SHOWTYPE == 7 || this.listFrom[k].SHOWTYPE == 8) {
                searchcolumn.push({
                  "queryType": this.listFrom[k].IS_QUERY,
                  "showType": this.listFrom[k].SHOWTYPE,
                  "column": this.listFrom[k].FIELD_NAME+"_ID",
                  "value": this.queryParams[i+"_ID"],
                })
              } else {
                searchcolumn.push({
                  "queryType": this.listFrom[k].IS_QUERY,
                  "showType": this.listFrom[k].SHOWTYPE,
                  "column": this.listFrom[k].FIELD_NAME,
                  "value": this.queryParams[i],

                })
              }
            }
          }

        }
      }

      this.listQueryParams.searchcolumn = searchcolumn;
      this.listQueryParams.order = undefined;
      this.sdlistPOST();
      this.$refs.ref.clearSort()
    },


    //重置
    resetQuery() {
      this.queryParams = {};
      this.listQueryParams.chushenresult = undefined;
      this.listQueryParams.fushenresult = undefined;
      this.listQueryParams.searchcolumn = undefined;
      this.listQueryParams.order = undefined;
      this.sdlistPOST();
    },
    //排序
    sortChange(val) {
      this.listQueryParams.order = val;
      this.sdlistPOST();

    },

    //获取表头列表
    getshowfieldPost() {
      var level = "";
      if (this.rowNameIDrow.TYPE == "f") {//件
        level = "jian"
      } else if (this.rowNameIDrow.TYPE == "v") { //卷
        level = "juan"
      } else {//项目
        level = "xiangmu"
      }
      var fields = [];
      this.loading = true;
      getshowfield({
        level: level,
        categoryId: this.rowNameIDrow.CATEGORYID,
        menuId: this.$route.meta.menuId,
      }).then(res => {

        this.tableHeaderList = res.data;
        for (var i in res.data) {
          fields.push(res.data[i].FIELD_NAME)
        }
        this.listQueryParams.fields = fields.toString();
        this.sdlistPOST()

      })
    },

    //列表展示
    sdlistPOST() {
      if (this.listQueryParams.renwuid != undefined) {
        this.loading = true
        // console.log(this.queryParams, "sdlfjliu")
        sdlist(this.listQueryParams).then(res => {
          this.tableData = res.rows;
          this.total = res.total;
          this.loading = false;
        }).catch(res => {
          this.loading = false
        })
      }
    },
    //多选框选中数据
    handleSelectionChange(ids, single, multiple, selection) {
      console.log(ids, single, multiple, selection)
      this.ids = ids;
      this.single = single;
      this.multiple = multiple;
    },

    //提交
    submitTap() {

      if (this.listQueryParams.renwuid == undefined) {
        this.$message({ message: '请选择任务名称', type: 'warning' })
        return false
      } else {
        // if (this.multiple) {
        //   this.$message({message: '请选择要提交的数据哦', type: 'warning'})
        //   return false
        // } else {
        shendingtijiao({
          renwuid: this.listQueryParams.renwuid,

        }).then(res => {
          if (res.code == "200") {
            this.$modal.msgSuccess(res.msg);
            // this.sdlistPOST()
            this.getsdjoblistPOST();
          }
        })
        // }
      }
    },
    //关闭详情页面
    detailsHandleClose() {
      this.jianDetailsOpen = false;
      this.juanDetailsOpen = false;
    },


    //双击列表进入详情页面
    celldblclick(row) {
      console.log(row, "++++")
      var level = "";
      if (this.rowNameIDrow.TYPE == "f") {  //F 件
        level = 0
      } else if (this.rowNameIDrow.TYPE == "v") { //卷
        level = 1
      } else { //项目
        level = 3

      }
      this.celldbData = {
        id: row.ID,
        categoryId: this.rowNameIDrow.CATEGORYID,
        menuId: this.$route.meta.menuId,
        sub_table_name: this.listQueryParams.subTableName,
        label: row.TITLE ? row.TITLE : '暂无标题',
        level: level,
        ifSub_table_name: this.listQueryParams.subTableName,
        isDel: "0",  //判断是回收站数据还是接收收据 isDel:1  回收站    isDel:0 //离线接收、档案接收、在线接收
        tableHeaderList: this.tableHeaderList
      }
      this.$nextTick(() => {
        if (this.rowNameIDrow.TYPE == "f") {  //F 进入件详情
          this.jianDetailsOpen = true;
        } else { //进入卷详情 和项目详情
          this.chuFushenParams = {
            renwuid: this.listQueryParams.renwuid,
            daid: row.ID,
            level: row.CATETYPE,
            type: "shending",
            // iskfjdorbgqx:0 //:iskfjdorbgqx="0"  开放鉴定   :iskfjdorbgqx="1" 保管期限
            iskfjdorbgqx: "0",
          }
          this.juanDetailsOpen = true
        }
      })

    },

    //调整审定结果
    handleSDJGDeit(row) {
      let text = ""
      //if (row.SHENDING_STATE === "0" || row.SHENDING_STATE === null || row.SHENDING_STATE === '') {
      //     text = "开放"
      // } else {
      //     text = "控制"
      // }
      let index=1;
      //审定结果展示，当SHENDING_STATE为空时 是以FUSHEN_JIANDING 判断展示结果
      if(row.SHENDING_STATE === null || row.SHENDING_STATE === '') {
        if(row.FUSHEN_JIANDING === "1") index=0;
      }else{
        if (row.SHENDING_STATE === "1")index=0;
      }
      for(var i=0;i<this.dict.type.IS_OPENS.length;i++){
        if(index==this.dict.type.IS_OPENS[i].value) text = this.dict.type.IS_OPENS[i].label
      }
      this.$modal.confirm('确定要调整审定结果为' + text + '吗？').then(() => {
        changesdresult({
          renwuid: this.listQueryParams.renwuid,
          daid: row.ID
        }).then(res => {
          this.$modal.msgSuccess('操作成功')
          this.sdlistPOST()
        })

      }).catch(() => { });
    },




  }
}
</script>
<style lang="scss" scoped>
.el-divider {
  margin-top: 0;
}
</style>
